package com.my.article.feign;

import com.my.apis.article.IArticleClient;
import com.my.article.service.ApArticleService;
import com.my.model.article.dtos.ArticleDto;
import com.my.model.article.pojos.ApArticle;
import com.my.model.common.dtos.ResponseResult;
import com.my.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ArticleClient implements IArticleClient {
    @Autowired
    private ApArticleService apArticleService;

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    @Override
    @DeleteMapping("/api/v1/article/delete/{id}")
    public ResponseResult deleteArticle(@PathVariable("id") Long id) {
        return apArticleService.deleteArticle(id);
    }

    @Override
    @GetMapping("/api/v1/article/getById/{id}")
    public ApArticle getById(@PathVariable Long id) {
        if(id == null) {
            return null;
        }

        return apArticleService.getById(id);
    }
}
